package com.sinoglobal.dumping.adapter;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.sinoglobal.dumping.R;
import com.sinoglobal.dumping.bean.Dumpling_CardVo;
import com.sinoglobal.dumping.util.Dumpling_TimeUtils;

import java.util.ArrayList;

/**
 * 贺卡
 */
public class Dumpling_MakeCardsAdapter extends BaseAdapter {

    private Activity mActivity;

    public ArrayList<Dumpling_CardVo> getCards() {
        return cards;
    }

    private ArrayList<Dumpling_CardVo> cards;

    public Dumpling_MakeCardsAdapter(ArrayList<Dumpling_CardVo> list, Activity activity) {
        mActivity = activity;
        cards = list;
    }

    public void addMore(ArrayList<Dumpling_CardVo> list) {
        for (int i = 0; i < list.size(); i++) {
            cards.add(list.get(i));
        }
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return cards.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if (view == null) {
            viewHolder = new ViewHolder();
            view = View.inflate(mActivity, R.layout.dumpling_make_card_list_item, null);
            viewHolder.cardItem= (RelativeLayout) view.findViewById(R.id.dumpling_make_card_item);
            viewHolder.cardWish = (TextView) view.findViewById(R.id.dumpling_make_card_wish);
            viewHolder.cardDate = (TextView) view.findViewById(R.id.dumpling_make_card_date);
            viewHolder.cardReport = (TextView) view.findViewById(R.id.dumpling_make_card_report);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        viewHolder.cardWish.setText(cards.get(i).getCardWish());
        viewHolder.cardDate.setText(Dumpling_TimeUtils.parseTimestampToString(""+cards.get(i).getCreateDate()));
        if (3==cards.get(i).getStatus()){
            viewHolder.cardItem.setBackgroundColor(mActivity.getResources().getColor(R.color.dumpling_make_card_report_bg));
            viewHolder.cardReport.setVisibility(View.VISIBLE);
        }
        return view;
    }

    class ViewHolder {
        private RelativeLayout cardItem;
        public TextView cardWish;
        public TextView cardDate;
        public TextView cardReport;

    }
}
